<script setup lang="ts">
import { Delete, InfoFilled } from "@element-plus/icons-vue";
import { onMounted } from "vue";
import useUserRecord from "@/view/Record/utils/hook.ts";

const {
  recordList,
  getRecord,
  getUserRecord,
  phone,
  deleteRecord
} = useUserRecord()

onMounted(() => {
  getRecord()
})
</script>

<template>
  <el-card class="box-card">
    <div class="box-top">
      <el-input v-model="phone" placeholder="请输入手机号"/>
      <el-button type="primary" @click="getUserRecord">搜索</el-button>
      <el-button @click="getRecord">重置</el-button>
    </div>
    <div class="card-body-table">
      <el-table
        border
        class="el-table-box"
        ref="multipleTableRef"
        :data="recordList"
        style="width: 100%"
      >
        <el-table-column label="#" width="60" align="center" type="index"/>
        <el-table-column align="center" label="用户">
          <template #default="{row}">
            {{ row.userId?.username }}
          </template>
        </el-table-column>
        <el-table-column prop="exerciseTime" align="center" label="锻炼时间"/>
        <el-table-column prop="stepNumber" align="center" label="步数"/>
        <el-table-column prop="consume" align="center" label="消耗"/>
        <el-table-column prop="score" align="center" label="评分"/>
        <el-table-column prop="createAt" align="center" label="时间"/>
        <el-table-column align="center" label="控制" width="220">
          <template #default="{row}">
            <div class="operator-btn">
              <el-popconfirm
                width="200"
                @confirm="deleteRecord(row._id)"
                confirm-button-text="确定"
                cancel-button-text="取消"
                :icon="InfoFilled as any"
                icon-color="#f36b6c"
                title="您确定删除此记录吗?"
              >
                <template #reference>
                  <el-button type="danger" size="default" :icon="Delete as any" circle/>
                </template>
              </el-popconfirm>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </el-card>
</template>

<style scoped lang="scss">
.box-card {
  padding: 0 50px;

  .box-top {
    display: flex;
    flex-direction: row;

    .el-input {
      width: 400px;
      margin-right: 20px;
    }
  }

  .card-body-table {
    margin-top: 20px;

    .el-table-box {
      height: calc(90vh - 110px);
    }
  }
}
</style>
